# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
"""
Card Data setttings
"""
__docformat__ = 'restructuredtext en'

# Card ranks, suits, colors ENUM
ACE = FIRST = PINE = BLACK = CLUBS = 0
TWO = SECOND = RED = HEARTS = 1
THREE = THIRD = SPADES = 2
FOUR = FOURTH = DIAMONDS = 3
FIVE = TRUMP = 4
SIX = 5
SEVEN = 6
EIGHT = 7
NINE = 8
TEN = 9
JACK = WILLOW = 10
QUEEN = RAJA = PAULOWNIA = 11
KING = 12
x10 = 15

SHORT_A7K = tuple([ACE] + range(SEVEN, KING + 1))
SHORT_A6K = tuple([ACE] + range(SIX, KING + 1))

# Special values for Stack.cap:
ANY = INFINITE = -1
GAP = MAX = 999999
NO_DEAL = 0
VARY = -2
NO_WRAP = 8192

CARDSET = _('cardset')

# cardset size
SIZE_TINY = 1
SIZE_SMALL = 2
SIZE_MEDIUM = 3
SIZE_LARGE = 4
SIZE_XLARGE = 5

# cardset types
TYPE_FRENCH = 1
TYPE_HANAFUDA = 2
TYPE_TAROCK = 3
TYPE_MAHJONGG = 4
TYPE_HEXADECK = 5
TYPE_MUGHAL_GANJIFA = 6
TYPE_NAVAGRAHA_GANJIFA = 7
TYPE_DASHAVATARA_GANJIFA = 8
TYPE_TRUMP_ONLY = 9


class French_Deck(object):
    _SUITS_ = {0: _('Club'), 1: _('Spade'), 2: _('Heart'), 3: _('Diamond')}
    _COLORS_ = {0: _('black'), 1: _('red')}
    _RANKS_ = {0: _('Ace'), 10: _('Jack'), 11: _('Queen'), 12: _('King'),
               ANY: _('Any card.'), GAP: _('No card')}

    _get_color = lambda self, suit: suit / 2
    _get_force = lambda self, suit: 0


class HexA_Deck(French_Deck):
    _RANKS_ = {0: _('Ace'), 9: 'A', 10: 'B', 11: 'C', 12: 'D', 13: 'E', 14:
               'F', 15: '10', ANY: _('Any card.'), GAP: _('No card')}

class Hanafuda_Deck(object):
    SUITS = {0: _("Pine"), 1: _("Plum"), 2: _("Cherry"), 3: _("Wisteria"),
             4: _("Iris"), 5: _("Peony"), 6: _("Bush Clover"),
             7: _("Eularia"), 8: _("Chrysanthemum"), 9: _("Maple"),
             10: _("Willow"), 11: _("Paulownia")}
    RANKS = {0: _('1st rank'), 1: _('2nd rank'), 2: _('3rd rank'),
             3: _('4th rank'), ANY: _('Any card.'), GAP: _('No card')}

    _get_color = lambda self, suit: 0
    _get_force = lambda self, suit: 0

class Tarock_Deck(French_Deck):
    SUITS = {0: _("Wand"), 1: _("Sword"), 2: _("Cup"), 3: _("Coin"),
             4: _("Trump")}
    RANKS = {1: _("Ace"), 10: _("Page"), 11: _("Valet"), 12: _("Queen"),
             13: _("King")}

    _get_color = lambda self, suit: suit % 2 if suit < 4 else 3


class Dashavatara_Deck(object):
    SUITS = (_("Fish"), _("Tortoise"), _("Boar"), _("Lion"), _("Dwarf"),
             _("Axe"), _("Arrow"), _("Plow"), _("Lotus"), _("Horse"))
    RANKS = (_("Ace"), "2", "3", "4", "5", "6", "7", "8", "9", "10",
             _("Pradhan"), _("Raja"))
    COLORS = (_("Black"), _("Red"), _("Yellow"), _("Green"), _("Brown"),
              _("Orange"), _("Grey"), _("White"), _("Olive"), _("Crimson"))
    FORCE = (_("Strong"), _("Weak"))

    _get_color = lambda self, suit: suit
    _get_force = lambda self, suit: 0 if suit > 5 else 1


class Mughal_Deck(object):
    SUITS = (_("Crown"), _("Silver"), _("Saber"), _("Servant"),
             _("Harp"), _("Gold"), _("Document"), _("Stores"))
    RANKS = (_("Ace"), "2", "3", "4", "5", "6", "7", "8", "9", "10",
             _("Pradhan"), _("Raja"))
    COLORS = (_("Brown"), _("Black"), _("Red"), _("Yellow"),
              _("Green"), _("Grey"), _("Orange"), _("Tan"))
    FORCE = (_("Strong"), _("Weak"))

    _get_color = lambda self, suit: suit
    _get_force = lambda self, suit: 0 if suit > 4 else 1


def verify_cardset(current, require):
    """
    Check current cardset with game requirements. Return cardset valid.

    *Parameters*:
      current : {CardsetDetail}
        details of chosen card set.
      require : {CardsetDetail}
        details of required card set.
    """
    from .group import TYPE
    assert isinstance(current, int) and isinstance(require, int)
    assert require in TYPE

    # Game types with 1-1 relationships to Cardset
    if (require in [TYPE_FRENCH, TYPE_HANAFUDA, TYPE_TAROCK,
                     TYPE_MAHJONGG, TYPE_HEXADECK, TYPE_TRUMP_ONLY]
        and current == require):
        return True

    # Larger Ganjifa decks can be used with smaller ones.
    ganjifa = [TYPE_DASHAVATARA_GANJIFA, TYPE_NAVAGRAHA_GANJIFA,
               TYPE_MUGHAL_GANJIFA]
    if (require in ganjifa and current in ganjifa and
          current_ in ganjifa[:ganjifa.index(current) + 1]):
        return True

    return False